from http.client import responses

import requests
from loguru import logger

from basic.base_login import merchant_login

def request_hook(response, *args, **kwargs):
    logger.info(f"接口响应信息为:{response.text}")

class BaseRequest:
    def __init__(self):
        self.session = requests.Session()
        self.session.hooks['response'].append(request_hook)
        self.request = self.session

class BaseMerchantRequest(BaseRequest):
    def __init__(self):
        super().__init__()
        self.request.headers.update({'authori-zation':merchant_login()})

    def post(self,api_name,url,json):
        logger.info(f"{api_name}-接口请求信息为:{json}")
        response = self.request.post(url=url,json=json)
        return response.json()

    def get(self,api_name,url,params=None):
        logger.info(f"{api_name}-接口请求信息为:{params}")
        response = self.request.get(url=url,params=params)
        return response.json()
